mod iter;

fn main() {
    // for num in 1..5 {
    //     println!("num is {}", num)
    // }
    //
    // for num in 1..=5 {
    //     println!("num is {}", num)
    // }

    let book_list = vec![
        "Rust编程入门",
        "Rust权威指南",
        "Rust系统编程",
    ];
    // for book in book_list.iter() {
    //     match book {
    //         &"Rust系统编程" => {
    //             println!("最抽象级别编程: {}", book)
    //         }
    //         _ => {
    //             println!("学习：{}", book)
    //         }
    //     }
    // }
    // for name in book_list.iter() {
    //     println!("{}", name)
    // }

    for book in book_list.into_iter() {
        match book {
            "Rust系统编程" => {
                println!("最抽象级别编程: {}", book)
            }
            _ => {
                println!("学习：{}", book)
            }
        }
    }
    // for name in book_list.iter() {
    //     println!("{}", name)
    // }

    let mut num = 1;
    while num < 20 {
        println!("num is {}", num);
        num = num * 2
    }

    let mut num2 = 1;
    loop {
        if num2 > 20 {
            break;
        }
        println!("num is {}", num2);
        num2 = num2 * 3;
    }

    let persons = vec!["张三", "李四", "王五"];
    // for p in persons {
    //     println!("{}", p);
    // }
    // println!("{:?}", persons);
    for p in &persons {
        // println!("{}", p);
        println!("String {:?} is at address {:p}", *p, p);
        // 自动解引用
        println!("String {} is at address {:p}", p, p);
    }
    println!("{:?}", &persons);
}